package com.example.lcode.backtrack;

import java.util.ArrayList;
import java.util.List;

public class Question46 {

    public List<List<Integer>> permute(int[] nums) {
        boolean []vis = new boolean[nums.length];
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> re = new ArrayList<>();
        permute(nums, res, re, vis);
        return res;
    }

    private void permute(int[] nums, List<List<Integer>> res, List<Integer> re ,boolean[] vis) {
        if (re.size() == nums.length) {
            res.add(new ArrayList<>(re));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (vis[i] == true) {
                continue;
            }
            vis[i] = true;
            re.add(nums[i]);
            permute(nums, res, re, vis);
            vis[i] = false;
            re.remove(re.size() - 1);
        }
    }

    public static void main(String[] args) {
        int []arr = {1};
        Question46 question46 = new Question46();
        List<List<Integer>> permute = question46.permute(arr);
        System.out.println(permute);
    }

}
